#!/bin/bash

# Get the display resolution using xrandr
resolution=$(xrandr | grep -oP '\d+x\d+' | head -n 1)

# Extract width and height from the resolution string
width=$(echo "$resolution" | cut -d 'x' -f 1)
height=$(echo "$resolution" | cut -d 'x' -f 2)

echo "Desktop resolution: $width x $height"



# Set the character dimensions of the terminal
columns=80
rows=24

# Set the font size (you might need to adjust this based on your actual font)
font_size=11

# Calculate pixel width and height based on character dimensions and font size
pixel_width=$((columns * font_size))
pixel_height=$((rows * font_size))

echo "Pixel size of gnome-terminal window: ${pixel_width}x${pixel_height}"

let col_num=$width/$pixel_width
echo "col_num:$col_num"

let col_want=3
let row_want=2

let col_pixel_step=$width/col_want
let row_pixel_step=$width/col_want

for((k=0;k<row_want;++k))
do
    for((i=0;i<col_want;++i))
    do
        let x=$i*$col_pixel_step
        let y=$k*$row_pixel_step

        gnome-terminal --geometry=80x24+$x+$y -- bash -c "gnome-terminal --tab --working-directory=$HOME; gnome-terminal --tab --working-directory=$HOME" &
        sleep 0.1 
    done
done

#gnome-terminal --geometry=80x24+0+0 -- bash -c "gnome-terminal --tab --working-directory=$HOME; gnome-terminal --tab --working-directory=$HOME" &

#gnome-terminal --geometry=80x24+0+0 &
#gnome-terminal --geometry=80x24+800+0 &
#gnome-terminal --geometry=80x24+0+500 &
#gnome-terminal --geometry=80x24+800+500 &
